<?php
/**
 * 会员控制器
 */
namespace Admin\Controller;
use Think\Controller;
class UserController extends InitController {

	// 会员列表
	public function memberList(){
		$topmenu = $this->topmenu;
		$sidebarmenu = $this->sidebarmenu[I('get.k')];

		// 获取等级列表
		$level_list = getMemberLevelList(true);

		$mobile = I('mobile');   //手机号码
		$member_name = I('member_name'); //会员昵称
		$weixin = I('weixin');  //微信号
		$member_level = I('member_level',-1,'intval'); //会员等级
		$member_status = I('member_status',-1,'intval');//会员状态
		$member_super_agent = I('member_super_agent',-1,'intval'); //总代理
		$start_time = strtotime(I('start_time'));         //开始时间
		$end_time = strtotime(I('end_time'));             //结束时间
		$parent_id = I('parent_id');         //推荐人编号
		$parent_name = I('parent_name','');              //推荐人昵称

		$where = array();                                  //关联where
		$left_join_where = "where 1";                               //关联子查询
		$left_join_sql   = "left join";                   //没有查询的时候是左联接

		if (!empty($mobile)) {
			$where['u.mobile'] = array('LIKE', '%'.$mobile.'%');
		}

		if (!empty($member_name)) {
			$where['u.username'] = array('LIKE', '%'.$member_name.'%');
		}

		if (!empty($weixin)) {
			$where['u.weixin'] = array('LIKE', '%'.$weixin.'%');
		}

		if ($level_list[$member_level]) {
			$where['u.level'] = $member_level;
		}

		if ($member_status != -1) {
			$where['u.status'] = $member_status == 1 ? 1 : 0;
		}
		else {
			$where['u.status'] = array('NEQ',-1);
		}

		if ($member_super_agent != -1) {
			$where['u.super_agent'] = $member_super_agent == 1 ? 1 : 0;
		}

		if (!empty($start_time) && !empty($end_time)) {
			// 如果有开始及结束时间 则取中值
			$where['u.createtime'] = array(array('EGT', $start_time), array('ELT', $end_time));
		}else{
			if (!empty($start_time)) {
				// 有开始时间 
				$where['u.createtime'] = array('EGT', $start_time);
			}elseif (!empty($end_time)) {
				// 有结束时间 
				$where['u.createtime'] = array('ELT', $end_time);
			}
		}

		//推荐人昵称 ,推荐人编号
		if(!empty($parent_id)){
			$left_join_where .= " and a.user_id = ".$parent_id."";
			$left_join_sql    = " inner join";                           //有查询的时候是内链接
		}

		//推荐人编号
		if(!empty($parent_name)){
			$left_join_where .= " and b.username like '%".$parent_name."%'";
			$left_join_sql    = " inner join";                           //有查询的时候是内链接
		}

		//所有数据
		$total = M("User")->alias('u')->join(''.$left_join_sql.' (SELECT a.subordinate_user,b.username AS fans_name,a.user_id FROM `ng_user_relationship` AS a LEFT JOIN `ng_user` AS b ON a.user_id = b.id '.$left_join_where.') AS r ON r.subordinate_user = u.id ')->where($where)->count();

		$Page = $this->setPageHander($total);
		$show = $Page?$Page->show():'';

		//查询数据
		$member_list = M('User')->alias('u')->field('u.id,u.mobile,u.createtime,u.level,u.username,u.weixin,u.status,u.super_agent,r.user_id AS recommend_id,r.fans_name')
			->join(''.$left_join_sql.' (SELECT a.subordinate_user,b.username AS fans_name,a.user_id FROM `ng_user_relationship` AS a LEFT JOIN `ng_user` AS b ON a.user_id = b.id '.$left_join_where.') AS r ON r.subordinate_user = u.id ')
			->where($where)
			->limit($Page->firstRow.','.$Page->listRows)
			->order('u.id desc')
			->select();

		/*$member_list = M('user')->field('id,mobile,createtime,level,username,weixin,status,super_agent')
						->where($where)
						->limit($Page->firstRow.','.$Page->listRows)
						->order('id desc')
						->select();

		foreach($member_list as $k=>$v){
			//查询推介人
			$user_id = M('UserRelationship')->where(array("subordinate_user"=>$v['id']))->getField('user_id');
			$member_list[$k]['fans_name'] = M('User')->where(array('id'=>$user_id))->getField("username");
		}*/
	
		$this->assign(array(
			'level_list' => $level_list,	// 等级列表
			'member_list' => $member_list,
			'mobile' => $mobile,
			'member_name' => $member_name,
			'weixin' => $weixin,
			'member_level' => $member_level,
			'member_status' => $member_status,
			'start_time' => $start_time,
			'end_time' => $end_time,
			'member_super_agent'=>$member_super_agent,
			'pager'=>$show,
			'parent_id'=>$parent_id,
			'parent_name'=>$parent_name
		));
		
		$this->assign('topmenu',$topmenu);
		$this->assign('sidebarmenu',$sidebarmenu);
		$this->display('memberList');
	}

	// 会员锁定/解锁
	public function memberLock()
	{

		if (!IS_AJAX) {
			$this->ajaxReturn(array('error'=>1,'errmsg'=>'非法操作！','field'=>''));
		}

		$status = I('status',0,'intval');
		$id = I('uid',0,'intval');

		if(!$id){
			$this->ajaxReturn(array('error'=>1,'errmsg'=>'参数错误！','field'=>''));
		}

		$memberModel = D('User');
		$userStatus = $memberModel->getMemberStatus($id);

		if($status == $userStatus){
			$this->ajaxReturn(array('error'=>0,'errmsg'=>'操作成功！','field'=>''));
		}

		if ($memberModel->changeStatus($status,$id)) {
			$this->ajaxReturn(array('error'=>0,'errmsg'=>'操作成功！','field'=>''));
		}else{
			$this->ajaxReturn(array('error'=>1,'errmsg'=>'操作失败！','field'=>''));
		}
	}

	// 查询会员下线
	public function downMember()
	{
		$topmenu = $this->topmenu;
		$sidebarmenu = $this->sidebarmenu[I('get.k')];

		$uid = I('uid',0,'intval');
		if (!$uid) {
			$this->error('非法操作！');
		}

		// 获取等级列表
		$level_list = getMemberLevelList(true);

		$memberModel = D('User');
		$user_info = $memberModel->getMemberInfoById($uid); //用户信息
		$total = $memberModel->getDownMemberNum($uid);
		
		$Page = $this->setPageHander($total);
		$show = $Page?$Page->show():'';
		$limit = '';
		if($Page != false){
			$limit = $Page->firstRow.','.$Page->listRows;
		}
		$down_member_list = $memberModel->getDownMember($uid, 'id desc' , $limit);
		
	
		$this->assign(array(
			'level_list' => $level_list,	// 等级列表
			'user_info' => $user_info,		// 会员详细信息
			'down_member_num' => $total,	// 下级数量
			'down_member_list' => $down_member_list,	// 下级列表
			'pager'=>$show
		));
		$this->assign('topmenu',$topmenu);
		$this->assign('sidebarmenu',$sidebarmenu);
		$this->display('downMember');
	}

	// 会员详细
	public function memberInfo()
	{
		$topmenu = $this->topmenu;
		$sidebarmenu = $this->sidebarmenu[I('get.k')];

		$id = I('uid',0,'intval');
		if (!$id) {
			$this->error('非法操作！');
		}

		// 获取等级列表
		$level_list = getMemberLevelList();

		$memberModel = D('User');
		$user_info = $memberModel->getMemberInfoById($id);

		$this->assign(array(
			'level_list' => $level_list,	// 等级列表
			'user_info' => $user_info,		// 会员详细信息
		));
		$this->assign('topmenu',$topmenu);
		$this->assign('sidebarmenu',$sidebarmenu);
		$this->display('memberInfo');
	}

	public function changememberInfo()
	{
		$id = I('uid',0,'intval');

		if (!$id) {
			$this->ajaxReturn(array('error'=>1,'errmsg'=>'参数错误！','field'=>''));
		}

		$memberModel = D('User');
		$user_info = $memberModel->getMemberInfoById($id);

		// 获取等级列表
		$level_list = getMemberLevelList();

		$password = I('password','','strip_tags,htmlspecialchars,trim');
		$username = I('username','','strip_tags,htmlspecialchars,trim');
		$weixin = I('weixin','','strip_tags,htmlspecialchars,trim');
		$level = I('level',0,'intval');
		$valid_time = I('valid_time','0','strip_tags,htmlspecialchars,trim,strtotime');
		$status = I('status',0,'intval');

		// 总代理
		$super_agent = I('super_agent',0,'intval');

		// 密码无效
		if (!empty($password)) {
			if (!is_password($password)) {
				$this->ajaxReturn(array('error'=>1,'errmsg'=>'密码必须6位以上20位以下字符组成！','field'=>'password'));
			}
		}

		$data = array();	// 更新数组
		if ($password)
		{
			// 密码
			$data['password'] = md5($password);
		}

		if ($level != $user_info['level'])
		{
			// 等级是否有效等级
			if (empty($level_list[$level]))
			{
				// 改为非会员，重置有效时间
				$data['level'] = 0;
				$data['valid_time'] = 0;
			}
			else
			{
				$data['level'] = $level;
				//$data['valid_time'] = 0;
				$data['valid_time'] = $valid_time?$valid_time:0;
			}
		}else{
			$data['valid_time'] = $valid_time?$valid_time:0;
		}

		$data['username'] = $username;
		$data['weixin'] = $weixin;
		$data['status'] = $status ? $status : 0;
		
		if ($memberModel->where(array('id' => $id))->save($data) === false)
		{
			$this->ajaxReturn(array('error'=>1,'errmsg'=>'操作失败！','field'=>''));
		}
		else
		{
			// 修改中代理状态
			$memberModel->changeSuperAgent($id, $super_agent);

			$this->ajaxReturn(array('error'=>0,'errmsg'=>'会员信息修改成功！','field'=>''));
		}
	}
    
	
	// 审核会员列表
	public function memberCheck() {
		
		$topmenu = $this->topmenu;
		$sidebarmenu = $this->sidebarmenu[I('get.k')];
		
		$member_model = D('User');
		$total = $member_model->getCheckNum(); //统计数量
		$Page = $this->setPageHander($total); //返回页数
		$show = $Page?$Page->show():'';       //是否显示
		$list = $member_model->memberCheckList($Page->firstRow.','.$Page->listRows);
		
		$this->assign('list',$list);
		$this->assign('pager',$show);
		$this->assign('topmenu',$topmenu);
		$this->assign('sidebarmenu',$sidebarmenu);
		$this->display('User/memberCheck');
	}
	
	//审核异步
	public function memberAjax(){
		$item_id = I('id',0,'intval');
		$status  = I('status',0,'intval');
		if(empty($item_id)){
			$this->ajaxReturn(array('error'=>1,'errmsg'=>'非法操作！','field'=>''));
		}
		if(empty($status)){
			$this->ajaxReturn(array('error'=>1,'errmsg'=>'非法操作！','field'=>''));
		}
		$member_model = D('User');
		$result = $member_model->passUser($item_id,$status);
		if($result){
			$this->ajaxReturn(array('error'=>0,'errmsg'=>'操作成功！','field'=>''));
		}else{
			$this->ajaxReturn(array('error'=>1,'errmsg'=>'非法操作！','field'=>''));
		}
		
	}

	
	//会员升级支付流水
	public function user_paylog_list(){
		$topmenu = $this->topmenu;
		$sidebarmenu = $this->sidebarmenu[I('get.k')];
	
		$username = I('username');
		$start_time = strtotime(I('start_time'));
		$end_time = strtotime(I('end_time'));
		
		$flow = I('flow');

		if(!empty($flow)){
			$where['ul.pay_flow'] = array("like",'%'.$flow.'%');
		}
		
		$pay_type = I('pay_type');

		if($pay_type !== ''){
			$where['ul.pay_type'] = $pay_type;
		}
		if($username){
			$where['u.username'] = array("like",'%'.$username.'%');
		}
		
		if (!empty($start_time) && !empty($end_time)) {
			// 如果有开始及结束时间 则取中值
			$where['ul.pay_time'] = array(array('EGT', $start_time), array('ELT', $end_time));
		}else{
			if (!empty($start_time)) {
				// 有开始时间 
				$where['ul.pay_time'] = array('EGT', $start_time);
			}elseif (!empty($end_time)) {
				// 有结束时间 
				$where['ul.pay_time'] = array('ELT', $end_time);
			}
		}

		$where['ul.is_paid'] = 1;

		//excel导出
		$Excel = I('excel');

		if($Excel){
			$fileName = "会员详情";

			$headArr = array("会员编号","会员昵称","支付类型","上一次会员期限","支付金额(元)","支付时间","支付流水号","备注");
			
			$list = M('UserUpgradeLog')->alias('ul')
						->field('ul.*,u.mobile,u.username,l.level_name')
						->join('LEFT JOIN __USER__ as u ON u.id = ul.user_id')
						->join('LEFT JOIN __LEVEL__ as l ON l.level_id = ul.upgrade_level')
						->where($where)
						->order('ul.id desc')
						->select();
		

			$data = array();

			foreach($list as $k => $v){
				$data[$k][] = $v['id'];
				$data[$k][] = $v['username'];

				if($v['pay_type'] == 1){
					$data[$k][] = "微支付";
				}elseif($v['pay_type'] == 2){
					$data[$k][] = "支付宝";
				}

				if($v['previous_time'] == 0){
					$data[$k][] = "免费会员";
				}else{
					$data[$k][] = date("Y-m-d",$v['previous_time']);
				}

				$data[$k][] = $v['pay_amount'];
				$data[$k][] = date("Y-m-d",$v['pay_time']);
				$data[$k][] = $v['pay_flow'];
				$data[$k][] = "升级为：".$v['level_name'];
			}

			ImportExcel($fileName,$headArr,$data);
			die;
		}
	
		
		
		$total = M('UserUpgradeLog')->alias('ul')
						->field('ul.*,u.mobile,u.username,l.level_name')
						->join('LEFT JOIN __USER__ as u ON u.id = ul.user_id')
						->join('LEFT JOIN __LEVEL__ as l ON l.level_id = ul.upgrade_level')
						->where($where)
						->count();

		$Page = $this->setPageHander($total);
		$show = $Page?$Page->show():'';
		
		$member_list = M('UserUpgradeLog')->alias('ul')
						->field('ul.*,u.mobile,u.username,l.level_name')
						->join('LEFT JOIN __USER__ as u ON u.id = ul.user_id')
						->join('LEFT JOIN __LEVEL__ as l ON l.level_id = ul.upgrade_level')
						->where($where)
						->limit($Page->firstRow.','.$Page->listRows)
						->order('ul.id desc')
						->select();
		
		$this->assign('username',$username);
		$this->assign('pay_type',$pay_type);
		$this->assign('flow',$flow);
		$this->assign('pay_type',$pay_type);
		$this->assign('pager',$show);
		$this->assign('list',$member_list);
		$this->assign('topmenu',$topmenu);
		$this->assign('sidebarmenu',$sidebarmenu);
		$this->display('User/user_paylog_list');
	}

	//会员佣金列表
	public function commissionList(){
		$topmenu = $this->topmenu;
		$sidebarmenu = $this->sidebarmenu[I('get.k')];
		
		$where = array();

		$username = I('username');
		
		if(!empty($username)){
			$where['u.username'] = array('like','%'.$username.'%');
		}

		$buyusername = I('buyusername');
		if(!empty($buyusername)){
			$where['bu.username'] = array('like','%'.$buyusername.'%');
		}

		$start_time = I('get.start_time','','strip_tags,htmlspecialchars,trim');
		$end_time = I('get.end_time','','strip_tags,htmlspecialchars,trim');
	
		if ($start_time !== '') {
			$start_time = strtotime($start_time);
			$this->assign('start_time',$start_time);
		}
		
		if ($end_time !== '') {
			$end_time = strtotime($end_time);
			$this->assign('end_time',$end_time);
		}
		
		if (!empty($start_time) && !empty($end_time)) {
			// 如果有开始及结束时间 则取中值
			$where['usi.createtime'] = array(array('EGT', $start_time), array('ELT', $end_time));
		}else{
			if (!empty($start_time)) {
				// 有开始时间
				$where['usi.createtime'] = array('EGT', $start_time);
			}elseif (!empty($end_time)) {
				// 有结束时间
				$where['usi.createtime'] = array('ELT', $end_time);
			}
		}

		//excel导出
		$Excel = I('excel');

		if($Excel){
			$fileName = "佣金收益情况";

			$headArr = array("编号","会员获的佣金(元)","佣金备注","推广者","注册者","支付时间");
			
			$list = M('UserSpreadIncome')->alias('usi')
					->join("left join __USER__ as u on usi.spreader = u.id")
					->join("left join __USER__ as bu on usi.register = bu.id")
					->where($where)->field('usi.id,usi.createtime,usi.commission,usi.remark,u.username,bu.username as buyusername')->select();

			$data = array();

			foreach($list as $k => $v){
				$data[$k][] = $v['id'];
				$data[$k][] = $v['commission']/100;
				$data[$k][] = $v['remark'];
				$data[$k][] = $v['username'];
				$data[$k][] = $v['buyusername'];
				$data[$k][] = date('Y-m-j',$v['createtime']);
			}

			ImportExcel($fileName,$headArr,$data);
			die;
		}

		$total = M('user_spread_income')->alias('usi')
		->join("left join __USER__ as u on usi.spreader = u.id")
		->join("left join __USER__ as bu on usi.register = bu.id")
		->where($where)->count('usi.id');
		
		$Page = $this->setPageHander($total);
		$show = $Page?$Page->show():'';
		
		$list = M('user_spread_income')->alias('usi')
					->join("left join __USER__ as u on usi.spreader = u.id")
					->join("left join __USER__ as bu on usi.register = bu.id")
					->where($where)->field('usi.id,usi.createtime,usi.commission,usi.remark,u.username,bu.username as buyusername')->limit($Page->firstRow.','.$Page->listRows)->select();
		
		$this->assign('list',$list);
		$this->assign('pager',$show);
		$this->assign('topmenu',$topmenu);
		$this->assign('sidebarmenu',$sidebarmenu);
		
		$this->assign('username',$username);
		$this->assign('buyusername',$buyusername);

		$this->display('User/commissionList');
	}

	//会员佣金收益情况
	public function commission(){
		$topmenu = $this->topmenu;
		$sidebarmenu = $this->sidebarmenu[I('get.k')];
		$uid = I('uid',0,'intval');
		if(!$uid){
			$this->error('参数错误！');
		}
		$userinfo = M('User')->where(array('id'=>$uid))->find();
		if(empty($userinfo)){
			$this->error('没有找到相应会员数据！');
		}
		//推广总收入
		$totalCommission = M('User_spread_income')->where(array('spreader'=>$uid))->sum('commission');//单位是分
		if($totalCommission){
			$totalCommission = round($totalCommission / 100,2);
		}
		
		//已提现佣金
		$ytx_commission = M('Withdrawal_apply')->where(array('status'=>1,'uid'=>$uid))->sum('money');//单位元
		
		//申请提现处理中金额
		$sqtx_commission = M('Withdrawal_apply')->where(array('status'=>0,'uid'=>$uid))->sum('money');//单位元
		
		//可提现佣金
		$cantx_commission = $totalCommission - $ytx_commission - $sqtx_commission;
		
		$this->assign('userinfo',$userinfo);
		$this->assign('totalCommission',$totalCommission + 0);
		$this->assign('ytx_commission',$ytx_commission + 0);
		$this->assign('sqtx_commission',$sqtx_commission + 0);
		$this->assign('cantx_commission',$cantx_commission + 0);
		
		$this->assign('topmenu',$topmenu);
		$this->assign('sidebarmenu',$sidebarmenu);
		$this->display('commission');
	}

	//会员广告
	public function adList(){
		$topmenu = $this->topmenu;
		$sidebarmenu = $this->sidebarmenu[I('get.k')];
		
		$articleModel = M('Ad');
		$title = I('title');
		$username = I('username');
		$uid = I('uid');
		$type = I('type');

		$start_time = strtotime(I('start_time'));
		$end_time = strtotime(I('end_time'));

		if($title){
			$where['a.title'] = array("like",'%'.$title.'%');
		}

		if($username){
			$where['u.username'] = array("like",'%'.$username.'%');
		}

		if($uid){
			$where['u.id'] = $uid;
		}

		if($type == '-1'){
			$where['a.type'] = 0;
		}else{
			if($type){
				$where['a.type'] = $type;
			}
		}

		// 文章状态
		$statePass = I('statePass',0,'intval'); // 已通过
		$stateVeto = I('stateVeto',0,'intval'); // 被否决

		if($statePass || $stateVeto)
		{
			$stateWhere = array();
			if ($statePass) {
				$stateWhere[] = '1';
			}
			if ($stateVeto) {
				$stateWhere[] = '-1';
			}
			$where['a.status'] = array('in',$stateWhere);
		}
		else
		{
			// 无选择时即全选
			$statePass = 1;
			$stateVeto = 1;
		}
		
		if (!empty($start_time) && !empty($end_time)) {
			// 如果有开始及结束时间 则取中值
			$where['a.createtime'] = array(array('EGT', $start_time), array('ELT', $end_time));
		}else{
			if (!empty($start_time)) {
				// 有开始时间 
				$where['a.createtime'] = array('EGT', $start_time);
			}elseif (!empty($end_time)) {
				// 有结束时间 
				$where['a.createtime'] = array('ELT', $end_time);
			}
		}

		$sort = I('sort',1,'intval');

		$sortList = array(
			'1' => array('name' => '时间↓','sql' => 'a.createtime desc'),
			'2' => array('name' => '时间↑','sql' => 'a.createtime asc'),
		);

		$order = $sortList[$sort]['sql'];

		$total = $articleModel->alias('a')->join("left join __USER__ as u on u.id = a.uid")->where($where)->count('a.id');

		$Page = $this->setPageHander($total);
		$show = $Page?$Page->show():'';

		$list = $articleModel->alias('a')->join("left join __USER__ as u on u.id = a.uid")->where($where)->order($order)->limit("{$Page->firstRow},{$Page->listRows}")->field("a.*,u.username,u.id as uid")->select();

		$this->assign('uid',$uid);
		$this->assign('list',$list);
		$this->assign('pager',$show);
		$this->assign('type',$type);
		$this->assign('topmenu',$topmenu);
		$this->assign('sidebarmenu',$sidebarmenu);
		$this->assign('start_time',$start_time);
		$this->assign('end_time',$end_time);
		$this->assign('title',$title);
		$this->assign('username',$username);
		$this->assign(array(
			'statePass' => $statePass,
			'stateVeto' => $stateVeto,
		));
		$this->assign(array(
			'sortList' => $sortList,
			'sort' => $sort,
		));
		$this->display('adlist');
	}

	// 批量通过
	public function adBatchPass()
	{
		if (!IS_AJAX)
		{
			$this->ajaxReturn(array('error' => 1, 'errmsg' => '非法操作！', 'field' => ''));
		}

		$batchId = I('batchId',array());

		if (empty($batchId)) {
			$this->ajaxReturn(array('error' => 1, 'errmsg' => '参数错误！', 'field' => ''));
		}

		$where = array('id' => array('in',array_values($batchId)));
			
		$result = M('Ad')->where($where)->save(array('status' => 1));
			
		if ($result !== false) {
			$this->ajaxReturn(array('error' => 0, 'errmsg' => $result.' 广告[通过]审核！', 'field' => ''));
		} else {
			$this->ajaxReturn(array('error' => 1, 'errmsg' => '操作失败！', 'field' => ''));
		}
	}

	// 批量否决
	public function adBatchVeto()
	{
		if (!IS_AJAX)
		{
			$this->ajaxReturn(array('error' => 1, 'errmsg' => '非法操作！', 'field' => ''));
		}

		$batchId = I('batchId',array());

		if (empty($batchId)) {
			$this->ajaxReturn(array('error' => 1, 'errmsg' => '参数错误！', 'field' => ''));
		}
			
		$where = array('id' => array('in',array_values($batchId)));
			
		$result = M('Ad')->where($where)->save(array('status' => -1));
			
		if ($result !== false) {
			$this->ajaxReturn(array('error' => 0, 'errmsg' => $result.' 广告[禁止发布]成功！', 'field' => ''));
		} else {
			$this->ajaxReturn(array('error' => 1, 'errmsg' => '操作失败！', 'field' => ''));
		}
	}

	//审核会员广告
	public function adEdit(){
		$id = I('id',0,'intval');
		if (!$id) {
			$this->error('参数错误');
		}
		$topmenu = $this->topmenu;
		$sidebarmenu = $this->sidebarmenu[I('get.k')];
		
        
        $articleModel = M('Ad');
        $data = $articleModel->where(array("id"=>$id))->find();	
       
        if($data['img_id'] != 0){
        	$data['thumb'] = M('ImageMaterial')->where(array("id"=>$data['img_id']))->getField('img_path');
        }

        $this->assign('info',$data);
		$this->assign('topmenu',$topmenu);
		$this->assign('sidebarmenu',$sidebarmenu);
		$this->display('adedit');
	}

	// 审核会员广告操作
	public function adCheckpass(){
		if(!IS_AJAX){
			return false;
		}
		$id = I('id',0,'intval');
		$status = I('status',0,'intval');
		
		if(empty($id)){
			$this->ajaxReturn(array('error'=>'-1','errmsg'=>'操作失败','field'=>''));
		}

		$rc = M('Ad')->where(array("id"=>$id))->save(array('status'=>$status));

		if($rc !== false){
			$this->ajaxReturn(array('error'=>'0','errmsg'=>'操作成功','field'=>'','url'=>U('adList',array('k'=>2,'sk'=>2))));
		}else{
			$this->ajaxReturn(array('error'=>'-1','errmsg'=>'操作失败','field'=>''));
		}
	}
	

}